Skip to content

fix(auth): don't call a login cancelled when it saved before Ctrl-C - #484

Merged
lihbr merged 1 commit into
lihbr/device-flowfrom
lihbr/device-flow-c4-fixes
Nov 13, 2026
Merged

lihbr merged 1 commit into
lihbr/device-flowfrom
lihbr/device-flow-c4-fixes

Conversation

@lihbr

@lihbr lihbr commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Resolves:

Description

A Ctrl-C right after approving a login could print "Login cancelled." even though the login had saved. The save keeps the credentials lock while it revokes the previous session. The Ctrl-C handler waited for that lock, found nothing left to cancel, and still reported a cancel, in telemetry too. Now it prints "Logged in to Prismic." and records a success. It still exits 130.

This fixes one of the two Bugbot findings on #469. The other one, "Login wipes session if keychain locked", stays as it is on purpose. Only an explicit prismic login replaces a saved login it can't read, and that's the recovery the keychain error suggests. Keeping the old login until the new one saves would mean not saving the pending login, so an agent's next run couldn't continue it.

Proved with a local run of the built CLI that held the previous session's revoke for 2 seconds: the base printed "Login cancelled." and this branch prints "Logged in to Prismic.". The new e2e test does the same.

Checklist

  • If my changes require tests, I added them.
  • If my changes affect backward compatibility, it has been discussed.
  • If my changes require an update to the CONTRIBUTING.md guide, I updated it.

Preview

$ prismic login
Open this URL on any device to log in:
  https://auth0.prismic.io/activate?user_code=BCDF-GHJK
Check that the page shows the code BCDF-GHJK.
Waiting for the login (the code expires in 15 minutes)...
^C
Logged in to Prismic.

How to QA 1

The Ctrl-C has to land during the save, which is hard to time by hand. The test "reports a login that saved before Ctrl-C as saved" in test/login.test.ts reproduces it.

Reviewed with sol-loop: 1 round with gpt-6.1-sol on high. Sol verdict: approved

Created with Claude Opus 5.5 in Claude Code.


Note

Low Risk
Narrow change to SIGINT handling and login outcome reporting; core save/revoke logic is unchanged aside from recording save state earlier.

Overview
Fixes a race where Ctrl-C during post-approval cleanup (while credentials are saved and the previous refresh token is revoked under the lock) still printed "Login cancelled." and logged telemetry as cancelled even though the session was already persisted.

The login flow now tracks when credentials are written via login.saved, and the SIGINT handler uses that to emit "Logged in to Prismic.", record success (including store metadata), and still exit 130 when interruption happens after a save; otherwise behavior stays cancelled.

Tests: fake Auth0 supports delayMs on one-off responses to hold /oauth/revoke, plus an e2e case that approves login, interrupts during revoke, and asserts the saved outcome messaging.

Reviewed by Cursor Bugbot for commit af30626. Bugbot is set up for automated code reviews on this repo. Configure here.

Footnotes

  1. Please use these labels when submitting a review:
    ❓ #ask: Ask a question.
    💡 #idea: Suggest an idea.
    ⚠️ #issue: Strongly suggest a change.
    🎉 #nice: Share a compliment. ↩

saveLogin() holds the credentials lock while it writes the new login and
revokes the previous session. A Ctrl-C in that window waited for the lock,
found the pending login already replaced, and still printed "Login
cancelled." with telemetry "cancelled", although the login was saved.
The handler now checks whether the login saved and says so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lihbr
lihbr merged commit a228b58 into lihbr/device-flow Nov 13, 2026
15 checks passed
@lihbr
lihbr deleted the lihbr/device-flow-c4-fixes branch November 13, 2026 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant